home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / VideoFolder 1.0a / Source / MoreFiles 1.4.1 / IterateDirectory.p < prev    next >
Text File  |  1995-12-21  |  6KB  |  134 lines

  1. UNIT IterateDirectory;
  2.  
  3. {    IterateDirectory: File Manager directory iterator routines.                }
  4. {                                                                            }
  5. {    by Jim Luther                                                            }
  6. {                                                                            }
  7. {    File:        IterateDirectory.p                                            }
  8. {                                                                            }
  9. {    Copyright © 1995 Jim Luther                                                }
  10. {    All rights reserved.                                                    }
  11. {                                                                            }
  12. {    You may incorporate this sample code into your applications without        }
  13. {    restriction, though the sample code has been provided "AS IS" and the    }
  14. {    responsibility for its operation is 100% yours.                            }
  15. {                                                                            }
  16. {    IterateDirectory is designed to drop into the MoreFiles sample code        }
  17. {    library I wrote while in Apple Developer Technical Support                }
  18.  
  19.  
  20. INTERFACE
  21.  
  22.     USES
  23.         Files;
  24.  
  25. {***************************************************************************}
  26.  
  27.  
  28.     TYPE
  29.         IterateFilterProcPtr = ProcPtr;
  30. {    A IterateDirectory IterateFilterProc procedure should have the            }
  31. {    following form:                                                            }
  32. {                                                                            }
  33. {    PROCEDURE MyIterateFilterProcPtr (cpbPtr: CInfoPBRec;                    }
  34. {                                      VAR quitFlag: Boolean;                }
  35. {                                      yourDataPtr: Ptr);                    }
  36. {                                                                            }
  37. {    This is the prototype for the IterateFilterProc function which is        }
  38. {    called once for each file and directory found by IterateDirectory. The    }
  39. {    IterateFilterProc gets a pointer to the CInfoPBRec that                    }
  40. {    IterateDirectory used to call PBGetCatInfo. The IterateFilterProc can    }
  41. {    use the read-only data in the CInfoPBRec for whatever it wants.            }
  42. {                                                                            }
  43. {    If the IterateFilterProc wants to stop IterateDirectory, it can set        }
  44. {    quitFlag to true (quitFlag will be passed to the IterateFilterProc        }
  45. {    false).                                                                    }
  46. {                                                                            }
  47. {    The yourDataPtr parameter can point to whatever data structure you        }
  48. {    might want to access from within the IterateFilterProc.                    }
  49. {                                                                            }
  50. {    cpbPtr        input:    A pointer to the CInfoPBRec that IterateDirectory    }
  51. {                        used to call PBGetCatInfo. The CInfoPBRec and the    }
  52. {                        data it points to must not be changed by your        }
  53. {                        IterateFilterProc.                                    }
  54. {    quitFlag    output:    Your IterateFilterProc can set quitFlag to true        }
  55. {                        if it wants to stop IterateDirectory.                }
  56. {    yourDataPtr    input:    A pointer to whatever data structure you might        }
  57. {                        want to access from within the IterateFilterProc.    }
  58.  
  59.  
  60. {***************************************************************************}
  61.  
  62.  
  63.     FUNCTION IterateDirectory (vRefNum: Integer;
  64.                                     dirID: LongInt;
  65.                                     name: StringPtr;
  66.                                     maxLevels: Integer;
  67.                                     iterateFilter: IterateFilterProcPtr;
  68.                                     yourDataPtr: Ptr): OSErr;
  69. {    The IterateDirectory function performs a recursive iteration (scan) of    }
  70. {    the specified directory and calls your IterateFilterProc function once    }
  71. {    for each file and directory found.                                        }
  72. {                                                                            }
  73. {    The maxLevels parameter lets you control how deep the recursion goes.    }
  74. {    If maxLevels is 1, IterateDirectory only scans the specified directory;    }
  75. {    if maxLevels is 2, IterateDirectory scans the specified directory and    }
  76. {    one subdirectory below the specified directory; etc. Set maxLevels to    }
  77. {    zero to scan all levels.                                                }
  78. {                                                                            }
  79. {    The yourDataPtr parameter can point to whatever data structure you         }
  80. {    might want to access from within the IterateFilterProc.                    }
  81. {                                                                            }
  82. {    vRefNum            input:    Volume specification.                            }
  83. {    dirID            input:    Directory ID.                                    }
  84. {    name            input:    Pointer to object name, or nil when dirID        }
  85. {                            specifies a directory that's the object.        }
  86. {    maxLevels        input:    Maximum number of directory levels to scan or    }
  87. {                            zero to scan all directory levels.                }
  88. {    iterateFilter    input:    A pointer to the routine you want called once    }
  89. {                            for each file and directory found by            }
  90. {                            IterateDirectory.                                }
  91. {    yourDataPtr        input:    A pointer to whatever data structure you might    }
  92. {                            want to access from within the                    }
  93. {                            IterateFilterProc.                                }
  94.  
  95.  
  96. {***************************************************************************}
  97.  
  98.  
  99.     FUNCTION FSpIterateDirectory ({CONST}
  100.                                     VAR spec: FSSpec;
  101.                                     maxLevels: Integer;
  102.                                     iterateFilter: IterateFilterProcPtr;
  103.                                     yourDataPtr: Ptr): OSErr;
  104. {    The FSpIterateDirectory function performs a recursive iteration (scan)    }
  105. {    of the specified directory and calls your IterateFilterProc function    }
  106. {    once for each file and directory found.                                    }
  107. {                                                                            }
  108. {    The maxLevels parameter lets you control how deep the recursion goes.    }
  109. {    If maxLevels is 1, FSpIterateDirectory only scans the specified            }
  110. {    directory; if maxLevels is 2, FSpIterateDirectory scans the specified    }
  111. {    directory and one subdirectory below the specified directory; etc.        }
  112. {    Set maxLevels to zero to scan all levels.                                }
  113. {                                                                            }
  114. {    The yourDataPtr parameter can point to whatever data structure you         }
  115. {    might want to access from within the IterateFilterProc.                    }
  116. {                                                                            }
  117. {    spec            input:    An FSSpec record specifying the directory to    }
  118. {                            scan.                                            }
  119. {    maxLevels        input:    Maximum number of directory levels to scan or    }
  120. {                            zero to scan all directory levels.                }
  121. {    iterateFilter    input:    A pointer to the routine you want called once    }
  122. {                            for each file and directory found by            }
  123. {                            IterateDirectory.                                }
  124. {    yourDataPtr        input:    A pointer to whatever data structure you might    }
  125. {                            want to access from within the                    }
  126. {                            IterateFilterProc.                                }
  127.  
  128.  
  129. {***************************************************************************}
  130.  
  131.  
  132. IMPLEMENTATION
  133.  
  134. END.